package com.hboxs.asl.controller.app.member;

import com.hboxs.asl.JsonMessage;
import com.hboxs.asl.Order;
import com.hboxs.asl.controller.app.BaseController;
import com.hboxs.asl.entity.Promotion;
import com.hboxs.asl.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by xxx on 2016/12/10
 * 促销接口
 */
@Controller(value = "appPromotionController")
@RequestMapping(value = "/app/m/promotion")
public class PromotionController extends BaseController {

    @Resource(name = "memberServiceImpl")
    private MemberService memberService;
    @Resource(name = "promotionServiceImpl")
    private PromotionService promotionService;
    @Resource(name = "cartServiceImpl")
    private CartService cartService;

    /**
     * 获取促销列表
     *
     * @return 促销列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public
    @ResponseBody
    Object list() {

        try {

            List<Order> os = new ArrayList<>();
            os.add(Order.desc("createDate"));
            List<Promotion> promotions = promotionService.findList(true, false, null, null, os);

            return JsonMessage.success(
                    JsonMessage.optimiseObj(promotions, "id", "name", "title", "type")
            );

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return JsonMessage.UNKNOWN_ERROR;
    }

}
